﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Sapper
{
    public class Sapper
    {
        int[,] mass;
        public int bomba = 10;
        bool[,] market = new bool[200, 200];
        public int schetchik = 0;
        public int oshibka = 0;
        public bool konec = false;
        public bool[,] Market
        {
            get { return market; }
            set { market = value; }
        }
        public void bfs(int i, int j)
        {
            if (mass[i, j] != 0)
            {
                konec = true;
                return;
            }
            bool[,] mark = new bool[mass.GetLength(0), mass.GetLength(1)];
            Point[] massi = new Point[10000];
            int beg = 0;
            int end = 1;
            massi[beg].X = i;
            massi[beg].Y = j;
            market[i, j] = true;
            while (beg != end)
            {
                for (int k = -1; k < 2; k++)
                {
                    for (int l = -1; l < 2; l++)
                    {
                        if (k == 0 && l == 0)
                        {
                            continue;
                        }
                        if (massi[beg].X + k >= 0 && massi[beg].X + k < mass.GetLength(0) && massi[beg].Y + l >= 0 && massi[beg].Y + l < mass.GetLength(1) && mass[massi[beg].X + k, massi[beg].Y + l] != -1)
                        {
                            if (market[massi[beg].X + k, massi[beg].Y + l] == false)
                            {
                                market[massi[beg].X + k, massi[beg].Y + l] = true;
                                schetchik++;
                            }
                            if (mass[massi[beg].X + k, massi[beg].Y + l] == 0 && mark[massi[beg].X + k, massi[beg].Y + l] == false)
                            {
                                massi[end].X = massi[beg].X + k;
                                massi[end].Y = massi[beg].Y + l;
                                mark[massi[beg].X + k, massi[beg].Y + l] = true;
                                end++;

                            }


                        }
                    }
                }
                beg++;
            }
            if (1 == 1)
            {
                konec = true;
            }
            if (mass[i, j] != 0)
            {
                oshibka = 1;
            }

        }
        public int[,] SozdIgri(int x, int y, int bomb)
        {
            mass = new int[x, y];
            int m, n;

            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    mass[i, j] = 0;
                }
            }
            Random rand = new Random();
            if (x * y <= bomb)
            {
                return mass;
            }
            for (int i = 0; i < bomb; i++)
            {

                m = rand.Next(x);
                n = rand.Next(y);
                if (mass[m, n] != -1)
                {
                    mass[m, n] = -1;
                    for (int k = -1; k < 2; k++)
                    {
                        for (int l = -1; l < 2; l++)
                        {
                            if (m + k >= 0 && m + k < x && n + l >= 0 && n + l < y && mass[m + k, n + l] != -1)
                            {
                                mass[m + k, n + l]++;
                            }
                        }
                    }
                }
                else
                {
                    i--;
                }

            }
            bomba = bomb;
            return mass;
        }

    }
}
